package picol.view.component;

import javax.swing.table.DefaultTableModel;

/**
 * 
 * @author Aurelien Marcel - Julien Sanderson
 */
public class ModelTableCounter extends DefaultTableModel {

    private String[] entetes = {"", ""};
    private static final int DEFAULT_COUNT_LINE = 20;

    public ModelTableCounter() {
        super();
        setRowCount(DEFAULT_COUNT_LINE);
        this.initLine();
    }

    @Override
    public String getColumnName(int columnIndex) {
        return entetes[columnIndex];
    }

    @Override
    public int getColumnCount() {
        return entetes.length;
    }

    @Override
    public boolean isCellEditable(int iRowIndex, int iColumnIndex) {
        return false;
    }

    private void initLine() {
        for (int i = 0; i < DEFAULT_COUNT_LINE; i++) {
            this.setValueAt(i + 1, i, 1);
            this.setValueAt(true, i, 0);
        }

    }

    public void addLine(int nbrow) {
        int rowcount = this.getRowCount();
        if (nbrow > rowcount) {
            String[] row = {"", ""};
            for (int i = rowcount; i < nbrow; i++) {
                this.addRow(row);
                this.setValueAt(i + 1, i, 1);
            }
        }

    }
}
